import BTDecorator from '../../Base/BTDecorator'
import { NodeStatus } from '../../Enum'

export default class DecoratorInverter extends BTDecorator {
  canExecute(): boolean {
    return this.status === NodeStatus.Inactive || this.status === NodeStatus.Running
  }
  onChildExecuted(status: NodeStatus): void {
    this.status = status
  }

  decorate(status: NodeStatus): NodeStatus {
    switch (status) {
      case NodeStatus.Success:
        return NodeStatus.Failure
      case NodeStatus.Failure:
        return NodeStatus.Success
      default:
        return status
    }
  }
}
